package com.snl.micro.blog.common.param;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserSaveParam {

    private String username;
    private String password;
    private String nickname;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime birthDay;
    private String imgUrl;
    private String email;
    private String phone;

    public void setBirthDay(String birthDay) {
        this.birthDay = gainBirthDay(birthDay);
    }

    private LocalDateTime gainBirthDay(String birth) {
        String year = birth.substring(0, 4);
        int index = birth.indexOf("-");
        String month = birth.substring(index + 1, index + 3);
        int index2 = birth.lastIndexOf("-");
        String day = birth.substring(index2 + 1, index2 + 3);
        int birthYear = Integer.parseInt(year);
        int birthMonth = Integer.parseInt(month);
        int birthDay = Integer.parseInt(day);
        return LocalDateTime.of(birthYear,birthMonth,birthDay,0,0,0);
    }
}
